package LanQiao._15JavaB;

import java.util.Scanner;

public class _4 {

    //WA  贪心局部最优出错
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int a2 = sc.nextInt();
            int a3 = sc.nextInt();
            int a4 = sc.nextInt();
            int b4 = sc.nextInt();
            int b6 = sc.nextInt();
            int helper = helper(a2, a3, a4, b4, b6);
            System.out.println(helper);
        }
        sc.close();

    }

    public static int helper(int a2, int a3, int a4, int b4, int b6) {
        int sum = 0;
        if (a3 / 2 * 6 >= b6 * 6) {
            sum += b6 * 6;
            a3 -= b6 * 2;
            b6 = 0;
        } else {
            sum += a3 / 2 * 6;
            b6 -= a3 / 2;
            a3 = a3 % 2;
        }
        int t = Math.min(a2, a4);
        if (t * 6 >= b6 * 6) {
            sum += b6 * 6;
            a2 -= b6;
            a4 -= b6;
            b6 = 0;
        } else {
            sum += t * 6;
            a2 -= t;
            a4 -= t;
            b6 -= t;
        }
        if (a4 >= b4) {
            sum += b4 * 4;
            a4 -= b4;
            b4 = 0;
        } else {
            sum += a4 * 4;
            b4 -= a4;
            a4 = 0;
        }
        if (a2 / 2 * 4 >= b4 * 4) {
            sum += b4 * 4;
            a2 -= b4 * 2;
            b4 = 0;
        } else {
            sum += a2 / 2 * 4;
            b4 -= a2 / 2;
            a2 = a2 % 2;
        }

        while (b6 > 0 && ((a3 > 0 && a2 > 0) || a4 > 0)) {
            if (a3 > 0 && a2 > 0) {
                sum += 5;
                a3--;
                a2--;
                b6--;
            } else {
                sum += 4;
                a4--;
                b6--;
            }
        }

        while (b4 > 0 && a3 > 0) {
            sum += 3;
            a3--;
            b4--;
        }

        while (b6 > 0 && a3 > 0) {
            sum += 3;
            a3--;
            b6--;
        }
        return sum;
    }

    /*
    1.满桌优先首先一定是让桌子都塞满人，这样利用率才能最大化。
    2.小桌优先先把人放到小桌中，因为小桌(4人桌)的人数组合搭配不够灵活，大桌(6人桌)可以有更多中组合搭配。
    3.人多优先寝室人多的先安置，因为人多不灵活，如果后面不能安置了，那么会损失很多人，利用率就下降了。
    4.空少优先当一个桌子不得不空出位置时，尽量少空出位置。(空出位置数相同时,优先排6人桌的，因为人相对于排4人桌更多)
    */
    public static int helper2(int a2, int a3, int a4, int b4, int b6) {
        int sum = 0;
        while (b4 > 0 && a4 >= 1) {
            b4--;
            a4--;
            sum += 4;
        }
        //满座匹配2x2人寝坐4人桌
        while (b4 > 0 && a2 >= 2) {
            b4--;
            a2 -= 2;
            sum += 4;
        }
        //满座匹配2+4人寝坐6人桌
        while (b6 > 0 && a4 >= 1 && a2 >= 1) {
            b6--;
            a4--;
            a2--;
            sum += 6;
        }
        //满座匹配2x3人寝坐6人桌
        while (b6 > 0 && a3 >= 2) {
            b6--;
            a3 -= 2;
            sum += 6;
        }
        //满座匹配3x2人寝坐6人桌
        while (b6 > 0 && a2 >= 3) {
            b6--;
            a2 -= 3;
            sum += 6;
        }
        //空1座匹配2+3人寝坐6人桌
        while (b6 > 0 && a2 >= 1 && a3 >= 1) {
            b6--;
            a2--;
            a3--;
            sum += 5;
        }
        //空1座匹配3人寝坐4人桌
        while (b4 > 0 && a3 > 0) {
            b4--;
            a3--;
            sum += 3;
        }
        //空2座匹配2x2人寝坐6人桌
        while (b6 > 0 && a2 >= 2) {
            b6--;
            a2 -= 2;
            sum += 4;
        }
        //空2座匹配4人寝坐6人桌
        while (b6 > 0 && a4 > 0) {
            b6--;
            a4--;
            sum += 4;
        }
        //空2座匹配2人寝坐4人桌
        while (b4 > 0 && a2 > 0) {
            b4--;
            a2--;
            sum += 2;
        }
        //空3座匹配3人寝坐6人桌
        while (b6 > 0 && a3 > 0) {
            b6--;
            a3--;
            sum += 3;
        }
        //空4座匹配2人寝坐6人桌
        while (b6 > 0 && a2 > 0) {
            b6--;
            a2--;
            sum += 2;
        }
        return sum;
    }

}


